<?php
/**
 *
 * @revision:   $Id: helper.php 18 2011-05-06 18:31:28Z agbiggora@gmail.com $
 * @package	    Joomla!
 * @since       {SINCE}
 * @subpackage	AG Yandex Metrika
 * @version     {PROJECTVERSION}
 * @description Module add Yandex Metrics code in your website
 * @copyright	Copyright © 2010-{PROJECTYEAR} Alexey Gordeyev IK. All rights reserved.
 * @license		GNU General Public License v2.0
 * @author		ALEXEY GORDEYEV IK
 * @author mail	admin@gordejev.lv
 * @website		www.gordejev.lv
 *
 * CODE GENERATED BY: ALEXEY GORDEYEV IK CODE GENERATOR
 * HTTP://WWW.AGJOOMLA.COM/
 *
 *
 * The module methods
 * -------------------------------
 * getCode()
 *
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
 * Module Helper ModAgyandexmetrika
 *
 * @package		Joomla!
 * @since       {SINCE}
 * @subpackage	AG Yandex Metrika
 * @version 	{PROJECTVERSION}
 * @class       ModAgyandexmetrikaHelper
 */

class ModAgyandexmetrikaHelper
{
   /**
    * Do something getCode method
    *
    * @param    array
    * @return   string
    */
   public function getCode($params)
   {
      # Counter params
      $ym_number        = $params->get('ym_number');
      $ym_type          = $params->get('ym_type');
      $ym_code          = $params->get('ym_code');
      $ym_linkmap       = $params->get('ym_linkmap');
      $ym_exlinks       = $params->get('ym_exlinks');
      # Informer params
      $ym_infsize       = $params->get('ym_infsize');
      $ym_incnt         = $params->get('ym_incnt');
      $ym_infbgcolor1   = $params->get('ym_infbgcolor1');
      $ym_infbgcolor2   = $params->get('ym_infbgcolor2');
      $ym_infgradient   = $params->get('ym_infgradient');
      $ym_inftextcolor  = $params->get('ym_inftextcolor');
      $ym_infarrowcolor = $params->get('ym_infarrowcolor');

      $output_code = "<!-- BEGIN AG YANDEX METRIKA MODULE v.{PROJECTVERSION} -->\n";
      if(!empty($ym_number)) {
         # Choise counter or (and) informer
         # Counter
         if($ym_code==0 || $ym_code==1 ) {
            # Choise counter type
            switch ($ym_type) {
               # Traditional
               case 0:
                  $output_code .= "<script src=\"//mc.yandex.ru/metrika/watch.js\" type=\"text/javascript\"></script>";
                  $output_code .= "<div style=\"display:none;\">";
                  $output_code .= "<script type=\"text/javascript\">";
                  $output_code .= "    try { var yaCounter".$ym_number." = new Ya.Metrika(".$ym_number.");} \n";

                  if($ym_linkmap == 1) {
                     $output_code .= "         yaCounter".$ym_number.".clickmap(true);\n";
                  }
                  if($ym_exlinks == 1) {
                     $output_code .= "         yaCounter".$ym_number.".trackLinks(true);\n";
                  }
                  $output_code .= "    catch(e) { } \n";
                  $output_code .= "</script>\n";
                  $output_code .= "</div>\n";
                  $output_code .= "<noscript><div>\n";
                  $output_code .= "<img src=\"//mc.yandex.ru/watch/".$ym_number."\" style=\"position:absolute; left:-9999px;\" alt=\"\" />";
                  $output_code .= "</div></noscript>\n";
                  break;
               # Asynhronous
               case 1:
                  $output_code .= "<div style=\"display:none;\"><script type=\"text/javascript\">\n";
                  $output_code .= "   (function(w, c) { \n";
                  $output_code .= "      (w[c] = w[c] || []).push(function() { \n";
                  $output_code .= "           try { \n";
                  $output_code .= "               w.yaCounter".$ym_number." = new Ya.Metrika(".$ym_number.");\n";
                  if($ym_linkmap == 1) {
                     $output_code .= "               yaCounter".$ym_number.".clickmap(true);\n";
                  }
                  if($ym_exlinks == 1) {
                     $output_code .= "               yaCounter".$ym_number.".trackLinks(true);\n";
                  }
                  $output_code .= "           } catch(e) { } \n";
                  $output_code .= "       }); \n";
                  $output_code .= "   })(window, 'yandex_metrika_callbacks');\n";
                  $output_code .= "</script></div>\n";
                  $output_code .= "<script src=\"//mc.yandex.ru/metrika/watch.js\" type=\"text/javascript\" defer=\"defer\"></script>\n";
                  $output_code .= "<noscript><div><img src=\"//mc.yandex.ru/watch/".$ym_number."\" style=\"position:absolute; left:-9999px;\" alt=\"\" /></div></noscript>\n";
                  break;
            }

         }
         # Informer
         if($ym_code==1 || $ym_code==2 ) {
            # Informer style
            /* Example  $info_style = "3_1_FFFFFFFF_EFEFEFFF_0_pageviews"; */
            $width = 88;
            $height = 31;
            switch ($ym_infsize) {
               case 1:
                  $width = 80;
                  $height = 15;
                  break;
               case 2:
                  $width = 80;
                  break;
               case 3:
                  $ym_incnt = "pageviews";
                  break;
               default;
            }
            $text_color = ($ym_inftextcolor)?$ym_inftextcolor:0;
            $arrow_color = ($ym_infarrowcolor)?$ym_infarrowcolor:0;

            $info_style = $ym_infsize."_".$arrow_color."_".strtoupper($ym_infbgcolor1)."_".strtoupper($ym_infbgcolor2)."_".$text_color."_".$ym_incnt;

            $output_code .= "<a href=\"http://metrika.yandex.ru/stat/?id=".$ym_number."&amp;from=informer\" ";
            $output_code .= "target=\"_blank\" rel=\"nofollow\"><img src=\"//bs.yandex.ru/informer/".$ym_number."/".$info_style."\" ";
            $output_code .= "style=\"width:".$width."px; height:".$height."px; border:0;\" alt=\"Яндекс.Метрика\" title=\"Яндекс.Метрика: данные за сегодня (просмотры, визиты и уникальные посетители)\" /></a>";
         }
         $output_code .= "<!-- END AG YANDEX METRIKA MODULE v.{PROJECTVERSION} -->\n";
         $output_code .= "<!-- ======= AUTHOR WWW.GORDEJEV.LV ======== -->\n";
      }
      return $output_code;
   } //end getCode

} // END ModAgyandexmetrikaHelper

?>